package org.example.spring.self.demo.pb;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 文件描述
 *
 * @author yezhou41127
 * @date: 2022年09月01日
 */
public class MainClass {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MainConfig.class);
		MessageService messageService = ctx.getBean(MessageService.class);
		MessageService2 messageService2 = ctx.getBean(MessageService2.class);
		messageService2.createMessage("1", "2");
		messageService2.createMessage("1", "2");

		//when
		messageService.createMessage("text", "alice");
		messageService.createMessage("msg", "bob");
		//then
		int prototypeCounter = MessageBuilder.getAdderCounter();

		System.out.println("Wrong number of instances " + 2 + " " + prototypeCounter);

		System.out.println(ctx.getBean(MessageService.class));
		System.out.println(ctx.getBean(MessageService.class));

		System.out.println(ctx.getBean(MessageBuilder.class));
		System.out.println(ctx.getBean(MessageBuilder.class));
	}
}
